﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        private Form assocatedForm = null;
        private bool isDrag = false;
        private bool isMouseDown = false;
        private int startX = 0;
        private int startY = 0;
        public Form2()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            this.assocatedForm.Text = "神奇的事情";
            if ( this.assocatedForm.WindowState == FormWindowState.Minimized )
            {
                this.assocatedForm.WindowState = FormWindowState.Maximized;
            }
            else
            {
                this.assocatedForm.WindowState = FormWindowState.Minimized;
            }
            
        }

        public void SetAssociateWindow(Form form) {
            
            this.assocatedForm = form;
            
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.BackColor = Color.Black;
            this.TransparencyKey = Color.Black;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            
        }
        
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.isMouseDown) {
                this.isDrag = true;
                //System.Console.WriteLine(e.X + "" +e.Y);
                int diffX = e.X - this.startX;
                int diffY = e.Y - this.startY;
                System.Console.WriteLine(this.Location);
                Point p = this.Location;
                p.X += diffX;
                p.Y += diffY;
                this.Location = p;
            }
          
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            this.isMouseDown = true;
            this.startX = e.X;
            this.startY = e.Y;
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!this.isDrag) {
                System.Console.WriteLine("刚刚是点击");
                this.assocatedForm.Text = "神奇的事情";
                if (this.assocatedForm.WindowState == FormWindowState.Minimized)
                {
                    this.assocatedForm.WindowState = FormWindowState.Maximized;
                }
                else
                {
                    this.assocatedForm.WindowState = FormWindowState.Minimized;
                }
            }
            this.isDrag = false;
            this.isMouseDown = false;
        }
    }
}
